package edu.jit.flowers.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.jit.flowers.bean.Users;
import edu.jit.flowers.service.UsersService;
import edu.jit.flowers.utils.BaseServlet;

public class MangerServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private UsersService uService = new UsersService();
	public String getAllManagersByRole(HttpServletRequest request, HttpServletResponse response) {
		List<Users> users = uService.getAllManagersByRole();
		request.setAttribute("users", users);
		return "forward:managerShow.jsp";
		// usersShow.jsp
	}
	public String addManger(HttpServletRequest request, HttpServletResponse response) {
		String username = request.getParameter("username");
		String realname = request.getParameter("realname");
		int age = Integer.parseInt(request.getParameter("age").trim());
		String tel = request.getParameter("tel");
		String gender = request.getParameter("gender");
		String address = request.getParameter("address");
		String password = request.getParameter("password");
		uService.addUsers(new Users(0, username, realname, age, tel, gender, password,1, address));
		return "redirect:Users?method=getAllUsersByRole";
	}
	public String updateUsersByUName(HttpServletRequest request, HttpServletResponse response) {
		String username = request.getParameter("username");
		String realname = request.getParameter("realname");
		int age = Integer.parseInt(request.getParameter("age").trim());
		String tel = request.getParameter("tel");
		String gender = request.getParameter("gender");
		String address = request.getParameter("address");
		String password = request.getParameter("password");
		uService.updateUsers(new Users(0, username, realname, age, tel, gender, password, 1, address));
		return "redirect:Users?method=getAllUsers";
	}
}
